﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PlaceMap.aspx.cs" Inherits="Tenancy.PlaceMap" %>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script src="Scripts/jquery-1.10.2.min.js"></script>
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=XVXZGRs7DzHeCqTfGTlmPuBFkwsLzBEm"></script>
	<title>地址解析</title>
</head>
<body>
	<div style="width:730px;margin:auto;" >   
        要查询的地址：<input id="cgs_Map_UserInfo" type="text" value="苏州市姑苏区" runat="server" style="margin-right:100px;"/>
        查询结果(经纬度)：<input id="result_" type="text" />
        <input type="button" value="查询" />
        <div id="container" 
            style="position: absolute;
                margin-top:30px; 
                width: 730px; 
                height: 590px; 
                top: 50px; 
                border: 1px solid gray;
                overflow:hidden;">
        </div>
       
    </div>
</body>
    <script type="text/javascript">
        var map = new BMap.Map("container");
        map.centerAndZoom("苏州", 12);
        map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
        map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

        map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
        map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
        map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开

        var localSearch = new BMap.LocalSearch(map);
        localSearch.enableAutoViewport(); //允许自动调节窗体大小
        //function searchByStationName() {
            map.clearOverlays();//清空原来的标注
            var keyword = document.getElementById("<%=cgs_Map_UserInfo.ClientID %>").value;
            localSearch.setSearchCompleteCallback(function (searchResult) {
                var poi = searchResult.getPoi(0);
                document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
                map.centerAndZoom(poi.point, 13);
                var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
                map.addOverlay(marker);
                var content = document.getElementById("<%=cgs_Map_UserInfo.ClientID %>").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
                alert(poi.point.lng);
                var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
                marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
                // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
            });
            localSearch.search(keyword);
       // }
</script>
    <%-- <script type="text/javascript">
         $(function () {
             var a = $('#result_').val();
             alert(a);
         });

        </script>--%>
</html>

